package cn.neusoft.luofa603.yuejian_29.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import cn.neusoft.luofa603.yuejian_29.R;
import cn.neusoft.luofa603.yuejian_29.activity.CourceInfoActivity;
import cn.neusoft.luofa603.yuejian_29.bean.Course;

public class CourseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public CourseAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    public class ViewHolder extends RecyclerView.ViewHolder{

        TextView cource_n;
        TextView bmnotice;
        TextView course_price;

        public ViewHolder(View itemView){

            super(itemView);
            cource_n=(TextView)itemView.findViewById(R.id.cource_n);
            bmnotice=(TextView)itemView.findViewById(R.id.bmnotice);
            course_price=(TextView)itemView.findViewById(R.id.course_price);;
        }

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.item_cource,parent,false);
        return new CourseAdapter.ViewHolder(v);
    }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

            final Course entity = (Course) mDataList.get(position);
            if (null==entity)
                return;
            CourseAdapter.ViewHolder viewHolder = (CourseAdapter.ViewHolder) holder;
            viewHolder.cource_n.setText(entity.getCourse_name());
            viewHolder.bmnotice.setText(entity.getBmnotice());
            viewHolder.course_price.setText("￥"+entity.getCourse_price());
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(mContext, CourceInfoActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("Course",entity);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }
            });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
}
